/*
 * Copyright (c) 2008, Xiong Yingfei, the University of Tokyo
 * All rights reserved.
 */
package ac.jp.u_tokyo.SyncLib.tests;

import static org.junit.Assert.assertEquals;

import org.antlr.runtime.RecognitionException;
import org.junit.Test;

import ac.jp.u_tokyo.SyncLib.Mod;
import ac.jp.u_tokyo.SyncLib.PrimMod;
import ac.jp.u_tokyo.SyncLib.dictionaries.DictModFactory;
import ac.jp.u_tokyo.SyncLib.modParser.ModParser;

public class ModParserTest
{
	@Test
	public void testParseInteger() throws RecognitionException {
		Mod[] mods = ModParser.parse("124");
		assertEquals(1, mods.length);
		assertEquals(new PrimMod<Integer>(124), mods[0]);
	}
	
	@Test
	public void testParseString() throws RecognitionException {
		Mod[] mods = ModParser.parse("\"124\"");
		assertEquals(1, mods.length);
		assertEquals(new PrimMod<String>("124"), mods[0]);
	}

	@Test
	public void testParseName() throws RecognitionException {
		Mod[] mods = ModParser.parse("abc23");
		assertEquals(1, mods.length);
		assertEquals(new PrimMod<String>("abc23"), mods[0]);
	}

	@Test
	public void testParseDictMod() throws RecognitionException {
		Mod[] mods = ModParser.parse("{name -> abc23}");
		assertEquals(1, mods.length);
		assertEquals(DictModFactory.creatvPut("name", new PrimMod<String>("abc23")), mods[0]);
	}
	
	@Test
	public void testParseNestedDictMod() throws RecognitionException {
		Mod[] mods = ModParser.parse("{name -> {23->null}}");
		assertEquals(1, mods.length);
		DictModFactory f = new DictModFactory();
		f.addPut("name", DictModFactory.creatvPut(23, PrimMod.NULL));
		assertEquals(f.create(), mods[0]);
	}


	@Test
	public void testParseTwoMods() throws RecognitionException {
		Mod[] mods = ModParser.parse("124, \"352\"");
		assertEquals(2, mods.length);
		assertEquals(new PrimMod<Integer>(124), mods[0]);
		assertEquals(new PrimMod<String>("352"), mods[1]);
	}

}
